package com.guoshengdeu.door.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoshengdeu.door.entity.ConfigVideo;
import com.guoshengdeu.door.entity.VoConfigVideo;
import com.guoshengdeu.door.service.IConfigVideoService;
import com.guoshengdeu.door.util.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yfly
 * @since 2021-06-01
 */
@Api("视频配置")
@RestController
@RequestMapping("/config-video")
public class ConfigVideoController {
//    @Resource(name = "videoService")
    @Autowired
    private IConfigVideoService configVideoService;

    //查询video
    @ApiOperation("查询")
    @RequestMapping("list")
    public List<ConfigVideo> queryVideo(){
        return configVideoService.list();
    }

    //去重查询分类
    @ApiOperation("去重查询分类")
    @GetMapping("querycatalog")
    public RespResult queryCateLog(){
        return RespResult.success(configVideoService.selectVideoCatalog());
    }

    //去重查询基地
    @ApiOperation("去重查询基地")
    @GetMapping("querybase")
    public RespResult queryBase(){
        return RespResult.success(configVideoService.selectVideoBase());
    }

    //去重查询学校
    @ApiOperation("去重查询学校")
    @GetMapping("queryschool")
    public RespResult querySchool(){
        return RespResult.success(configVideoService.selectVideoSchool());
    }

    //去重查询id、类别、名称
    @ApiOperation("去重查询id、类别、名称")
    @GetMapping("queryICN")
    public RespResult queryICN(){
        return RespResult.success(configVideoService.selectICN());
    }

    //添加更新
    @ApiOperation("添加更新")
    @RequestMapping("addvideo")
    public RespResult addVideo(@RequestBody ConfigVideo video){
        boolean saveOrUpdate = configVideoService.saveOrUpdate(video);
        if (saveOrUpdate){
            return RespResult.success();
        }
        return RespResult.error("添加或更新失败");
    }

    //删除video
    @ApiOperation("删除")
    @DeleteMapping("delevideo")
    public RespResult deleVideo(int id){
        boolean removeById = configVideoService.removeById(id);
        if(removeById){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }

    //分页
    @ApiOperation("分页")
    @GetMapping("page")
    public RespResult page(Page<ConfigVideo> page){
        Page<ConfigVideo> pages = configVideoService.page(page);
        return RespResult.success(pages);
    }
}
